home *** CD-ROM | disk | FTP | other *** search
- /* token.c is the token handling routine, which is filled
- * in with the routines executed when an action described by a token entry
- * is found.
- */
-
- /*
- Copyright Cornell University 1986. All rights are reserved.
-
- */
-
- #include <em.h>
-
- #include <cntldefs.h>
- #include <rcodes.h>
- #include <h19.h>
- #include <3270.h>
- #include <macdefs.h>
-
- short asciiflush; /* emdp->putflush needs to be called */
-
- proc_token(tkptr)
- struct token *tkptr;
- {
- switch(tkptr->class) {
- case RSLT_ASCI: {
- /* ascii character */
-
- if (emdp->conntype == CONN_MACTCP
- || emdp->conntype == CONN_CUTCP) {
- if (tkptr->entry == TNIAC)
- /* send IAC-IAC for IAC under Telnet */
- asciisendchar(TNIAC);
- }
- if (tkptr->entry == X_OFF)
- emdp->userxoff = TRUE;
- else
- emdp->userxoff = FALSE;
-
- if (asciisendchar(tkptr->entry))
- /* no room to buffer character */
- return(-1);
- break;
- }
- case RSLT_EDIT: {
- if (stdedit(tkptr->entry)) {
- /* stdedit didn't handle the item */
- if (tkptr->entry == ED_PASTE) {
- /* TODO: ASCII PASTE needs to be improved
- take the current scrap & feed it into proc_token?
- should handle echoing, timed line/character delays */
- long scraplen;
- unsigned char * thep;
- unsigned char thechar;
- long tickcount;
-
- scraplen = gettextscrap(&thep);
- while (scraplen-- > 0) {
- if ((thechar = *thep++) == CR) {
- /* do a CR/Line Feed when we see a CR */
- if (istcptype()) {
- /* telnet, send CR-LF */
- asciisendchar(CR);
- asciisendchar(LF);
- }
- else {
- if (emdp->ibm_keymode) {
- asciisendchar(LF); /* do LINE FEEDS like 3270 */
- }
- else {
- asciisendchar(CR);
- if (emdp->vtnewline)
- asciisendchar(LF);
- }
- }
- (*emdp->putflush)();
- Delay((long) 15, &tickcount);
- /* wait to make sure tiny host buffers serviced */
- /* TODO should handle by waiting for echo? */
- screen_service();
- }
- else {
- asciisendchar(thechar);
- }
- }
- releasescrap();
- break;
- }
- else
- entryerr(tkptr);
- }
- break;
- }
- case RSLT_PFKY: {
- /* program function key, enter, clear for 7171 compatibility */
- int thepf;
-
- thepf = 0;
- switch (tkptr->entry) {
- case PFSHIFT: {
- if (emdp->pfdubshift)
- break;
- if (!emdp->pfshift) {
- emdp->pfshift = TRUE;
- pfshowshift();
- }
- else {
- emdp->pfshift = FALSE;
- pfclrshift();
- }
- break;
- }
- case PFDUBSHIFT: {
- if (emdp->pfshift)
- break;
- if (emdp->pfdubshift) {
- emdp->pfdubshift = TRUE;
- pfshowdubshift();
- }
- else {
- emdp->pfdubshift = FALSE;
- pfclrdubshift();
- }
- break;
- }
- case PF1:
- case PF2:
- case PF3:
- case PF4:
- case PF5:
- case PF6:
- case PF7:
- case PF8:
- case PF9:
- case PF10:
- case PF11:
- case PF12:
- case PF13:
- case PF14:
- case PF15:
- case PF16:
- case PF17:
- case PF18:
- case PF19:
- case PF20:
- case PF21:
- case PF22:
- case PF23:
- case PF24: {
- thepf = tkptr->entry;
- break;
- }
- case PA1: {
- sendpa1();
- break;
- }
- case PA2: {
- sendpa2();
- break;
- }
- case PA3: {
- sendpa3();
- break;
- }
- case CLEAR: {
- sendClear();
- break;
- }
- case ENTER: {
- sendEnter();
- break;
- }
- default: {
- entryerr(tkptr);
- break;
- }
- }
- if (thepf != 0) {
- /* a pf key should be sent */
- if (emdp->pfshift) {
- emdp->pfshift = FALSE;
- emdp->pfdubshift = FALSE;
- pfclrshift();
- pfclrdubshift();
- thepf += 12;
- tkptr->entry += 12;
- }
- else if (emdp->pfdubshift) {
- emdp->pfshift = FALSE;
- emdp->pfdubshift = FALSE;
- pfclrshift();
- pfclrdubshift();
- thepf += 24;
- tkptr->entry += 24;
- }
- sendpf(thepf);
- }
- break;
- }
- case RSLT_MVCR: {
- /* IBM cursor movement key 7171 compatibility */
- switch (tkptr->entry) {
- case LEFT_ARROW: {
- sendLeft(1);
- break;
- }
- case RIGHT_ARROW: {
- sendRight(1);
- break;
- }
- case UP_ARROW: {
- sendUp(1);
- break;
- }
- case DOWN_ARROW: {
- sendDown(1);
- break;
- }
- case HOME: {
- sendHome();
- break;
- }
- case NEW_LINE: {
- sendNewline();
- break;
- }
- case TAB_FWD: {
- sendTab();
- break;
- }
- case BACK_TAB: {
- sendBackTab();
- break;
- }
- default: {
- entryerr(tkptr);
- }
- }
- break;
- }
- case RSLT_LCAC: {
- /* local action key */
- switch(tkptr->entry) {
- case BACKSP_BLANK: {
- sendBSblank();
- break;
- }
- case INSRT: {
- doinsert();
- break;
- }
- case ERASE_EOF: {
- sendErEOF();
- break;
- }
- case INPUT_ERASE: {
- sendErInput();
- break;
- }
- case BACKSP_DEL: {
- sendBSDEL();
- break;
- }
- case DEL_CHAR: {
- sendDEL();
- break;
- }
- case RESET: {
- sendReset();
- break;
- }
- default: {
- entryerr(tkptr);
- }
- }
- break;
- }
- case RSLT_YCURS: {
- /* move to beginning of line y */
- if (tkptr->entry < 0 || tkptr->entry > emdp->lastrow) {
- entryerr(tkptr);
- break;
- }
- emdp->gotoy = tkptr->entry;
- break;
- }
- case RSLT_XCURS: {
- /* move to an x location on current line */
- if (tkptr->entry < 0 || tkptr->entry > lastcol) {
- entryerr(tkptr);
- break;
- }
- if (emdp->gotoy != -1) {
- cursmoveto(tkptr->entry, emdp->gotoy);
- emdp->gotoy = -1;
- }
- else {
- cursmoveto(tkptr->entry, ypos);
- }
- break;
- }
- default: {
- if (stdtoken(tkptr))
- classerr(tkptr);
- }
- }
- return(0);
- }
-
-
- /* the following routines "send*" send 7171 translator specific sequences */
-
- sendpf(pfkey)
- int pfkey;
- {
- asciisendchar(ESC);
-
- switch (pfkey) {
- case 1: {
- asciisendchar('1');
- break;
- }
- case 2: {
- asciisendchar('2');
- break;
- }
- case 3: {
- asciisendchar('3');
- break;
- }
- case 4: {
- asciisendchar('4');
- break;
- }
- case 5: {
- asciisendchar('5');
- break;
- }
- case 6: {
- asciisendchar('6');
- break;
- }
- case 7: {
- asciisendchar('7');
- break;
- }
- case 8: {
- asciisendchar('8');
- break;
- }
- case 9: {
- asciisendchar('9');
- break;
- }
- case 10: {
- asciisendchar('0');
- break;
- }
- case 11: {
- asciisendchar('-');
- break;
- }
- case 12: {
- asciisendchar('=');
- break;
- }
- case 13: {
- asciisendchar('!');
- break;
- }
- case 14: {
- asciisendchar('@');
- break;
- }
- case 15: {
- asciisendchar('#');
- break;
- }
- case 16: {
- asciisendchar('$');
- break;
- }
- case 17: {
- asciisendchar('%');
- break;
- }
- case 18: {
- asciisendchar('^');
- break;
- }
- case 19: {
- asciisendchar('&');
- break;
- }
- case 20: {
- asciisendchar('*');
- break;
- }
- case 21: {
- asciisendchar('(');
- break;
- }
- case 22: {
- asciisendchar(')');
- break;
- }
- case 23: {
- asciisendchar('_');
- break;
- }
- case 24: {
- asciisendchar('+');
- break;
- }
- default: {
- error("Bad PF key code");
- }
- }
- savescreen();
- /* save the screen before it gets overwritten */
-
- }
-
- sendpa1()
- {
- if (emdp->event_reg & TFTP_ON) {
- /* cancel file transfer */
- ft_usr();
- }
- else {
- asciisendchar(ESC);
- asciisendchar(',');
-
- savescreen();
- /* save the screen before it gets overwritten */
-
- }
- }
-
- sendpa2()
- {
- asciisendchar(ESC);
- asciisendchar('.');
-
- savescreen();
- /* save the screen before it gets overwritten */
-
- }
-
- sendpa3()
- {
- asciisendchar(ESC);
- asciisendchar('/');
-
- savescreen();
- /* save the screen before it gets overwritten */
-
- }
-
- sendClear()
- {
- /* VT 7171 "keypad Enter" ? */
- asciisendchar(ESC);
- asciisendchar('?');
- asciisendchar('M');
-
- savescreen();
- /* save the screen before it gets overwritten */
-
- }
-
- sendInsert()
- {
- /* VT 7171 "keypad ." */
- asciisendchar(ESC);
- asciisendchar('?');
- asciisendchar('n');
- }
-
- /* toggle the switches, control highlighting, and send insert */
-
- doinsert()
- {
- sendInsert();
- if (emdp->event_reg & INSERT) {
- clrinsert();
- emdp->event_reg &= ~INSERT;
- }
- else {
- showinsert();
- emdp->event_reg |= INSERT;
- }
- }
-
-
- sendEnter()
- {
- asciisendchar(CR);
-
- savescreen();
- /* save the screen before it gets overwritten */
-
- }
-
- sendNewline()
- {
- asciisendchar(LF);
- }
-
- sendBSDEL()
- {
- sendLeft(1);
- asciisendchar(DELETE);
- }
-
- sendBSblank()
- {
- sendLeft(1);
- asciisendchar(' ');
- sendLeft(1);
- }
-
- sendTab()
- {
- asciisendchar(TAB);
- }
-
- sendBackTab()
- {
- asciisendchar(ESC);
- asciisendchar(TAB);
- }
-
- sendDEL()
- {
- asciisendchar(DELETE);
- }
-
-
- /* the vtaltcursor mode is only effective when in application keypad mode */
-
- sendUp(count)
- int count;
- {
- if (mode == VT100MODE) {
- int appkeypadmode;
- int altcursor;
-
- /* appkeypadmode = emdp->vtaltkeypad; incorrect, changed throughout ... */
- appkeypadmode = TRUE;
- altcursor = emdp->vtaltcursor;
- while (count--) {
- asciisendchar(ESC);
- asciisendchar(appkeypadmode ? altcursor : '[');
- asciisendchar('A');
- }
- }
- else {
- while (count--) {
- asciisendchar(ESC);
- asciisendchar('A');
- }
- }
- }
-
- sendDown(count)
- int count;
- {
- if (mode == VT100MODE) {
- int appkeypadmode;
- int altcursor;
-
- appkeypadmode = TRUE;
- altcursor = emdp->vtaltcursor;
- while (count--) {
- asciisendchar(ESC);
- asciisendchar(appkeypadmode ? altcursor : '[');
- asciisendchar('B');
- }
- }
- else {
- while (count--) {
- asciisendchar(ESC);
- asciisendchar('B');
- }
- }
- }
-
- sendLeft(count)
- int count;
- {
- if (mode == VT100MODE) {
- int appkeypadmode;
- int altcursor;
-
- appkeypadmode = TRUE;
- altcursor = emdp->vtaltcursor;
- while (count--) {
- asciisendchar(ESC);
- asciisendchar(appkeypadmode ? altcursor : '[');
- asciisendchar('D');
- }
- }
- else {
- while (count--) {
- asciisendchar(ESC);
- asciisendchar('D');
- }
- }
- }
-
- sendRight(count)
- int count;
- {
- if (mode == VT100MODE) {
- int appkeypadmode;
- int altcursor;
-
- appkeypadmode = TRUE;
- altcursor = emdp->vtaltcursor;
- while (count--) {
- asciisendchar(ESC);
- asciisendchar(appkeypadmode ? altcursor : '[');
- asciisendchar('C');
- }
- }
- else {
- while (count--) {
- asciisendchar(ESC);
- asciisendchar('C');
- }
- }
- }
-
- sendHome()
- {
- asciisendchar(BS);
- }
-
- sendErInput()
- {
- asciisendchar(ESC);
- asciisendchar('?');
- asciisendchar(DELETE);
- }
-
- sendErEOF()
- {
- asciisendchar(ESC);
- asciisendchar(DELETE);
- }
-
- sendReset()
- {
- if (emdp->termtype != TERM_3270)
- asciisendchar(CTLG); /* ^G */
-
- savescreen();
- /* save the screen before it gets overwritten */
-
- doreset();
- }
-
-
- /* move vi cursor to a vertical position yloc */
-
- sendvvimove(yloc)
- int yloc;
- {
- char temp[10];
- register char * tempp = temp;
-
- sprintf(tempp, "%d", yloc + 1);
- while (*tempp) {
- asciisendchar(*tempp++);
- }
- asciisendchar('H');
- /* vi command to move n lines from top of screen */
- }
-
-
- /* move vi cursor to a horizontal position xloc */
-
- sendhvimove(xloc)
- int xloc;
- {
- char temp[10];
- register char * tempp = temp;
-
- sprintf(tempp, "%d", xloc + 1);
- while (*tempp) {
- asciisendchar(*tempp++);
- }
- asciisendchar('|');
- /* vi command to move n lines from top of screen */
- }
-
-
- /* move emacs cursor to a vertical position yloc */
-
- sendvemacsmove(yloc)
- int yloc;
- {
- char temp[10];
- register char * tempp = temp;
-
- sprintf(tempp, "%d", yloc);
- while (*tempp) {
- asciisendchar(*tempp++);
- }
- /* asciisendchar('H'); */
- /* emacs command to move n lines from top of screen */
- }
-
-
- /* move emacs cursor to a horizontal position xloc */
-
- sendhemacsmove(xloc)
- int xloc;
- {
- char temp[10];
- register char * tempp = temp;
-
- sprintf(tempp, "%d", xloc);
- while (*tempp) {
- asciisendchar(*tempp++);
- }
- /* asciisendchar('|'); */
- /* emacs command to move n lines from top of screen */
- }
-
-
- /* Telnet sendchar: put out a character TODO local echo mode not healthy; should buffer line
- to preserve WYSIWYG */
-
- asciisendchar(schar)
- unsigned char schar;
- {
- if (!emdp->connopen)
- return(-1);
-
- if (emdp->event_reg & TFTP_ON)
- /* if not abort char, don't send anything */
- return(-1);
-
- if (emdp->ucb.u_sendm == EVERYC) {
- if ((*emdp->putchar)(schar)) {
- return(-1);
- }
- asciiflush = TRUE;
- }
- else {
- if (emdp->vtnewline) {
- /* LF will be the last char in the CR-LF output pair */
- if (schar == LF) {
- asciiflush = TRUE;
- }
- }
- else if (schar == CR) {
- /* end of line, send */
- asciiflush = TRUE;
- }
- if (asciiflush) {
- if ((*emdp->putchar)(CR)) {
- return(-1);
- }
- if ((*emdp->putchar)(LF)) {
- /* in vtnewline mode, we'll have added the newline already */
- return(-1);
- }
- }
- else {
- if ((*emdp->putchar)(schar)) {
- return(-1);
- }
- }
- }
- if (emdp->ucb.u_echom == LOCAL) {
- emprep();
- if (schar == CR) {
- (*emdp->em)(CR);
- (*emdp->em)(LF);
- }
- else if (schar == LF) {
- (*emdp->em)(LF);
- }
- else if ((schar >= ' ' && schar < DELETE) )
- (*emdp->em)(schar);
- else if (schar == C_BREAK || schar == CTLL)
- ;
- else if (schar == BS || schar == DELETE) {
- (*emdp->em)(BS);
- (*emdp->em)(' ');
- (*emdp->em)(BS);
- }
- else if (schar < ' ') {
- /* make a control character */
- (*emdp->em)('^');
- (*emdp->em)((char) schar + '@');
- }
- emend();
- }
- return(0);
- }
-
- /* send a string of characters */
-
- asciisendstr(strp)
- char * strp;
- {
- if (emdp->event_reg & TFTP_ON)
- /* if not abort char, don't send anything */
- return(-1);
-
- for ( ; *strp; strp++) {
- if ((*emdp->putchar)(*strp) ) {
- return(-1);
- }
- if (emdp->ucb.u_echom == LOCAL) {
- emprep();
- (*emdp->em)(*strp);
- setcursor();
- emend();
- }
- }
- (*emdp->putflush)();
- }
-
-
- /* send a Break */
-
- sendBreak()
- {
- if (emdp->conntype == CONN_MACTCP
- || emdp->conntype == CONN_CUTCP) {
- sendcommand(TNINT);
- sendsynch();
- }
- else if (emdp->conntype == CONN_SERD) {
- sersendBreak();
- }
- }
-
-
- /* send an IAC-command pair */
-
- sendcommand(tncom)
- int tncom;
- {
- (*emdp->putchar)(TNIAC);
- (*emdp->putchar)((char) tncom);
- (*emdp->putflush)();
- }
-
- /* send a telnet Synch sequence--URG + DM, DM, to cause host to flush non-control data */
-
- sendsynch()
- {
- mtcpurgent();
- sendcommand(TNDM);
- mtcpclrurgent();
- dotcpurgent();
- }
-
-
-
- /* here follows a mess of download file transfer support */
- /* 2 short routines to get file transfer going */
-
- /* for compatibility with c19 file transfer */
-
- sendftchar(tchar)
- char tchar;
- {
- (*emdp->putchar)(tchar);
- }
-
-
- /* move the cursor to the given x,y location */
-
- cursmoveto(xloc, yloc)
- int xloc;
- int yloc;
- {
- int count;
-
- if (emdp->ibm_keymode || (!emdp->curseekmode && ypos == yloc) ) {
- /* if ibm_keymode, move up or down without going to the left margin */
- /* else if on correct y move straight to emdp->xpos */
- count = xpos - xloc;
- if (count > 0) {
- /* move left */
- sendLeft(count);
- }
- else {
- /* move right */
- count = - count;
- sendRight(count);
- }
- if (emdp->ibm_keymode) {
- count = ypos - yloc;
- if (count > 0) {
- /* move up */
- sendUp(count);
- }
- else {
- /* move down */
- count = -count;
- sendDown(count);
- }
- }
- }
- else if (emdp->curseekmode) {
- /* == CURVIMODE */
- if (yloc != ypos)
- sendvvimove(yloc);
- if (xloc != xpos)
- sendhvimove(xloc);
- }
- #ifdef EMACSCAN
- else if (emdp->curseekmode == CUREMACSMODE) {
- if (yloc != ypos)
- sendvemacsmove(yloc);
- if (xloc != xpos)
- sendhemacsmove(xloc);
- }
- #endif
- else {
- /* slow standard method to move cursor to left margin */
- if (yloc != ypos) {
- sendLeft(xpos);
-
- /* move up or down */
- count = ypos - yloc;
- if (count > 0) {
- /* move up */
- sendUp(count);
- }
- else {
- /* move down */
- count = -count;
- sendDown(count);
- }
- sendRight(xloc);
- }
- /* move cursor left on same line */
- else if (xloc < xpos) {
- count = xpos - xloc;
- sendLeft(count);
- }
- /* move cursor right on same line */
- else if (xloc > xpos) {
- count = xloc - xpos;
- sendRight(count);
- }
- }
- /* flush the output buffers now that we've sent out the moves */
- (*emdp->putflush)();
- }
-
-